from Cryptodome.Cipher import AES
from Cryptodome.Util.Padding import pad,unpad
import hashlib

# AES 加密函数
def aes_encode(data: bytes, key: str) -> bytes:
    # 将 key 处理成 16 字节
    key_bytes = hashlib.md5(key.encode()).digest()  # 16字节的key
    cipher = AES.new(key_bytes, AES.MODE_ECB)
    encrypted = cipher.encrypt(pad(data, AES.block_size))
    return encrypted
# AES 解密
def aes_decode(encrypted_data: bytes, key: str ) -> bytes:
    key_bytes = hashlib.md5(key.encode()).digest()
    cipher = AES.new(key_bytes, AES.MODE_ECB)
    decrypted = unpad(cipher.decrypt(encrypted_data), AES.block_size)
    return decrypted


key = "Xw4V4c8v"


# 读取加载器代码文件路径
# aes_loader_aes_shellcode_loader
loader_file = '../aes_shellcode_loader.py'

# aes_loader_base64_shellcode_loader
# loader_file ='../base64_shellcode_loader.py'

# aes_loader_custom_base64_shellcode_loader
# loader_file ='../custom_base64_shellcode_loader.py'

# 读取加载器代码
with open(loader_file, 'rb') as f:
    code_bytes = f.read()

aes_bytes = aes_encode(code_bytes, key)
print(aes_bytes)



